/// 物流轨迹信息
class TrackingStep {
  final String time;
  final String content;
  final String? status;
  final String? statusDesc;

  TrackingStep({
    required this.time,
    required this.content,
    this.status,
    this.statusDesc,
  });

  factory TrackingStep.fromJson(Map<String, dynamic> json) {
    return TrackingStep(
      time: json['time'] as String,
      content: json['content'] as String,
      status: json['status'] as String?,
      statusDesc: json['status_desc'] as String?,
    );
  }
}

/// 快递追踪信息
class TrackingInfo {
  final String nu; // 快递编号
  final String? com; // 快递公司编码
  final String? comText; // 快递公司名称
  final int? state; // 签收状态，3已签收
  final String? status; // 最后一条物流状态
  final String? statusDesc; // 物流状态描述
  final List<TrackingStep> info; // 物流轨迹列表

  TrackingInfo({
    required this.nu,
    this.com,
    this.comText,
    this.state,
    this.status,
    this.statusDesc,
    required this.info,
  });

  factory TrackingInfo.fromJson(Map<String, dynamic> json) {
    return TrackingInfo(
      nu: json['nu'] as String,
      com: json['com'] as String?,
      comText: json['com_text'] as String?,
      state: json['state'] as int?,
      status: json['status'] as String?,
      statusDesc: json['status_desc'] as String?,
      info: (json['info'] as List<dynamic>?)
              ?.map((e) => TrackingStep.fromJson(e as Map<String, dynamic>))
              .toList() ??
          [],
    );
  }

  bool get isDelivered => state == 3;

  String get statusDisplay {
    if (statusDesc != null && statusDesc!.isNotEmpty) {
      return statusDesc!;
    }
    if (status != null && status!.isNotEmpty) {
      return status!;
    }
    return '未知状态';
  }
}

